<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/2
 * Time: 16:28
 */
namespace app\index\controller;

use think\Db;
use think\View;
use think\Controller;
use think\Session;
use think\Request;
class Capital  extends Controller
{
    //我的余额
    public function capital(){
        if (!Session('Login_userId') && !Session('Login_userName')) {
            $this->redirect('/login');die;
        }
        $memberId=Session('Login_userId');
        $account= Db::name('member_account')->where(array('memberId'=>$memberId))->value('account');
        $re=Db::name('member_account_log')->where('memberId',$memberId)->field('changeAccount,addDateTime,businessType,businessId')->order('addDateTime','desc')->limit(10)->select();
        foreach ($re as $k => $v){
            if($v['businessType']==3){
                $memberCashStatus=Db::name('member_cash')->where('memberCashId',$v['businessId'])->value('status');
                if($memberCashStatus==0){
                    $re[$k]['status']="审核中";
                }elseif ($memberCashStatus==1){
                    $re[$k]['status']="待兑付";
                }elseif ($memberCashStatus==3){
                    $re[$k]['status']="提现成功";
                }elseif ($memberCashStatus==2 || $memberCashStatus==4){
                    $re[$k]['status']="提现失败";
                }
                $re[$k]['typeName']="提现";
                $re[$k]['typeDetail']="提现";
            }elseif ($v['businessType']==4){
                $memberCashStatus=Db::name('member_cash')->where('memberCashId',$v['businessId'])->value('status');
                if($memberCashStatus==0){
                    $re[$k]['status']="审核中";
                }elseif ($memberCashStatus==1){
                    $re[$k]['status']="待扣除";
                }elseif ($memberCashStatus==3){
                    $re[$k]['status']="扣除成功";
                }elseif ($memberCashStatus==2 || $memberCashStatus==4){
                    $re[$k]['status']="扣除失败";
                }
                $re[$k]['typeName']="提现";
                $re[$k]['typeDetail']="手续费扣除";
            }elseif ($v['businessType']==5){
                $member=Db::name('service_order_commission')->where('serviceOrderCommissionId',$v['businessId'])->find();
                if($member['status']==0){
                    $re[$k]['status']="待返中";
                }elseif ($member['status']==1){
                    $re[$k]['status']="返现成功";
                }elseif ($member['status']==2){
                    $re[$k]['status']="返现失败";
                }
                $re[$k]['typeName']="返现";
                $re[$k]['typeDetail']="返现";
            }elseif ($v['businessType']==7){
                $memberCashStatus=Db::name('service_order')->where('serviceOrderId',$v['businessId'])->find();
                if($memberCashStatus['paymentStatus']==0){
                    $re[$k]['status']="待支付";
                }elseif ($memberCashStatus['paymentStatus']==1){
                    $re[$k]['status']="支付成功";
                }elseif ($memberCashStatus['paymentStatus']==2){
                    $re[$k]['status']="支付失败";
                }
                $serviceId=Db::name('service_order_service')->where('serviceOrderId',$memberCashStatus['serviceOrderId'])->value('serviceId');
                if($memberCashStatus['serviceType']==0 || $memberCashStatus['serviceType']==2 || $memberCashStatus['serviceType']==3){
                    $serviceName=Db::name('service')->where('serviceId',$serviceId)->value('serviceName');
                    $re[$k]['typeDetail']="服务商品".$serviceName."订单";
                }elseif ($memberCashStatus['serviceType']==1){
                    $project=Db::name('project')->where('projectId',$serviceId)->find();
                    if($project['projectType']==1){
                        $projectType="注册地址";
                    }elseif ($project['projectType']==2){
                        $projectType="众创空间";
                    }elseif ($project['projectType']==3){
                        $projectType="买卖执照";
                    }
                    $re[$k]['typeDetail']=$projectType.$project['projectName']."订单";
                } elseif ($memberCashStatus['serviceType']==4){

                    $re[$k]['typeDetail']="执照联系方式查看";
                }

                $re[$k]['typeName']="订单结算";

            }elseif ($v['businessType']==8){
                $member=Db::name('member_commission')->where('memberCommissionId',$v['businessId'])->find();
                if($member['status']==0){
                    $re[$k]['status']="待返中";
                }elseif ($member['status']==1){
                    $re[$k]['status']="返现成功";
                }elseif ($member['status']==2){
                    $re[$k]['status']="返现失败";
                }
                $providerName=Db::name('provider')->where('providerId',$member['providerId'])->value('providerName');
                $re[$k]['typeName']="推荐服务商奖金";
                $re[$k]['typeDetail']="推荐".$providerName."成为服务商推奖金";
            }elseif ($v['businessType']==10){
                $memberCashStatus=Db::name('member_recharge')->where('memberreChargeId',$v['businessId'])->value('status');
                if($memberCashStatus==0){
                    $re[$k]['status']="充值失败";
                }elseif ($memberCashStatus==1){
                    $re[$k]['status']="充值成功";
                }
                $re[$k]['typeName']="充值";
                $re[$k]['typeDetail']="充值";
            }elseif ($v['businessType']==9){
                $re[$k]['status']="提现失败";
                $re[$k]['typeName']="提现";
                $re[$k]['typeDetail']="提现";
            }
        }
        $this->view->assign('re',$re);
        $this->view->assign('account',$account);
        return view('balance');
    }
    //充值
    public function recharge(){
        return view('recharge');
    }
    //提现
    public function capitalcash()
    {
        return view('withdraw1');
    }
    //提现下一步
    public function capitalcash2()
    {
        return view('withdraw2');
    }
   //账户管理（绑定银行卡列表）
    public function cash(){
        return view('account');
    }
    //账户管理（添加银行卡）
    public function addBankCard(){
        return view('addbankcard');
    }
    //重设支付密码（验证）
    public  function phoneValidate(){
        return view('phonevalidate');
    }
    //重设支付密码（验证）
    public  function emailValidate(){
        return view('emailvalidate');
    }
    //重设支付密码
    public  function setPayPwd(){
        return view('setpaypwd');
    }
    //重设支付密码
    public  function setPayPwd2(){
        return view('setpaypwd2');
    }
}